package com.example.mybatisplus.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.Resident;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybatisplus.model.dto.BedInfoDTO;
import com.example.mybatisplus.model.dto.StudentCountDTO;
import com.example.mybatisplus.model.dto.UnderDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.jdbc.core.SqlProvider;

import java.util.List;
import java.util.Map;

// import static jdk.internal.org.jline.utils.Colors.s;
import static org.apache.coyote.http11.Constants.a;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lxp
 * @since 2024-07-17
 */
@Mapper
public interface ResidentMapper extends BaseMapper<Resident> {
    @Select("SELECT COUNT(*) FROM resident WHERE campus_id = #{campusId}")
    int countStudentsByCampusId(@Param("campusId") Long campusId);
    @Select("SELECT COUNT(*) FROM resident WHERE Bed_Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND type='本科生')")
    int getUndergraduateCount(@Param("areaname") String areaname, @Param("campusname") String campusname);
    @Select("SELECT COUNT(*) FROM resident WHERE Bed_Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND type='教职工')")
    int getTeacherCount(@Param("areaname") String areaname, @Param("campusname") String campusname);
    @Select("SELECT COUNT(*) FROM resident WHERE Bed_Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND type='硕士研究生')")
    int getMasterCount(@Param("areaname") String areaname, @Param("campusname") String campusname);
    @Select("SELECT COUNT(*) FROM resident WHERE Bed_Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND type='博士研究生')")
    int getDoctorCount(@Param("areaname") String areaname, @Param("campusname") String campusname);
    @Select("SELECT s.major, COUNT(*) as count FROM resident s JOIN area a ON s.Bed_Room_Building_Area_areaId= a.areaId WHERE a.areaName = #{areaName} AND a.campusName = #{campusName} AND s.type != '教职工' GROUP BY s.major")
    List<StudentCountDTO> getStudentCountByMajor(@Param("campusName") String campusName, @Param("areaName") String areaName);
    @Select("SELECT COUNT(*) FROM resident WHERE type = '本科生' AND isCheckin = 1")
    int countCheckedInUndergraduates();
    @Select("SELECT COUNT(*) FROM resident WHERE type = '本科生'")
    int countUndergraduates();
    @Select("SELECT COUNT(*) FROM resident WHERE type = '硕士研究生' AND isCheckin = 1")
    int countCheckedInMasters();
    @Select("SELECT COUNT(*) FROM resident WHERE type = '硕士研究生'")
    int countMasters();
    @Select("SELECT COUNT(*) FROM resident WHERE type = '博士研究生' AND isCheckin = 1")
    int countCheckedInPhds();
    @Select("SELECT COUNT(*) FROM resident WHERE type = '博士研究生'")
    int countPhds();
    @Select("SELECT COUNT(*) FROM resident WHERE type = '教职工' AND isCheckin = 1")
    int countCheckedInStaffs();
    @Select("SELECT COUNT(*) FROM resident WHERE type = '教职工'")
    int countStaffs();
//    List<UnderDTO> findUnderBed();
//    List<UnderDTO> findPostBed();
//    List<UnderDTO> findStaffBed();
//
//    Page<UnderDTO> findUnderBed(@Param("page")Page<UnderDTO> page,@Param("bedId") String bedId);
//    Page<UnderDTO> findPostBed(@Param("page")Page<UnderDTO> page,@Param("bedId") String bedId);
    Page<UnderDTO> findUnderBed(@Param("page")Page<UnderDTO> page,@Param("areaName") String areaName,@Param("buildingName") String buildingName,@Param("floor") String floor);
    Page<UnderDTO> findPostBed(@Param("page")Page<UnderDTO> page,@Param("areaName") String areaName,@Param("buildingName") String buildingName,@Param("floor") String floor);
//    List<UnderDTO> findPostBed();
    Page<UnderDTO> findStaffBed(@Param("page")Page<UnderDTO> page,@Param("areaName") String areaName,@Param("buildingName") String buildingName,@Param("floor") String floor);
}
